<template>
	<sc-table-select
		ref="tableselect"
		v-model="templatevalue"
		:attrList="attrList"
		:valueList="valueList"
		:queryList="queryList"
		:table-width="640"
		collapse-tags
		collapse-tags-tooltip
		:props="props"
		@change="change"
	>
		<template #header="{}">
			<el-form :inline="true">
				<el-row :gutter="5"
					><el-col :span="5">
						<el-input
							v-model="queryList.Code"
							placeholder="请输入编码"
							style="width: 120px"
						></el-input></el-col
					><el-col :span="5">
						<el-input
							v-model="queryList.Name"
							placeholder="请输入名称"
							style="width: 120px"
						></el-input> </el-col
					><el-col :span="5"
						><el-select
							v-model="queryList.TypeCode"
							placeholder="请选择类型"
							style="width: 120px"
							clearable
							:teleported="false"
						>
							<el-option
								v-for="item in optionsTypeCode"
								:key="item.value"
								:label="item.label"
								:value="item.value"
							/> </el-select></el-col
					><el-col :span="4">
						<el-button
							type="primary"
							@click="$refs.tableselect.getData()"
							>查询</el-button
						></el-col
					></el-row
				>
			</el-form>
		</template>
		<el-table-column prop="Code" label="编码" width="100"></el-table-column>
		<el-table-column prop="Name" label="名称" width="180"></el-table-column>
		<el-table-column
			prop="TypeName"
			label="类型"
			width="120"
		></el-table-column>
		<el-table-column
			prop="Remark"
			label="备注"
			width="200"
		></el-table-column>
	</sc-table-select>
</template>

<script>
import publicjs from "@/api/model/publicjs";
export default {
	name: "templateSelect",
	props: {
		orgCode: { type: String, default: "" },
	},
	data() {
		return {
			attrList: {
				Name: "Template",
				UseDistinct: false,
				OrgCode: "",
				UseBackUp: false,
				UseGroup: false,
			},
			valueList: {
				Code: "Code",
				Name: "Name",
				TypeName: "TypeName",
				Remark: "Remark",
			},
			queryList: {
				OrgCode: "",
				Code: "",
				Name: "",
				TypeCode: "",
				State: "1",
			},
			optionsTypeCode: [],
		};
	},
	methods: {
		async initOptions() {
			var head = new publicjs.head();
			publicjs.initHead(head, "getfirstdatasource");
			var ed = new publicjs.entitydata(head);
			var eo = new publicjs.entityobj();
			eo.AttrList = {
				Name: "Template",
				AcceptControl: "TypeCode",
				OrgCode: this.orgCode,
			};
			ed.Data.Content.ObjectList.Object.push(eo);
			try {
				var returnValueStr = await this.$API.auth.objProcess.post(ed);
				var returnValue = JSON.parse(returnValueStr);
				if (returnValue.Result.OpFlag == "1") {
					var objectList =
						returnValue.Result.Content.ObjectList.Object;
					this.optionsTypeCode = objectList.rows.row;
				} else {
					this.$message.error("操作失败:" + returnValue.Result.OpMsg);
				}
			} catch (error) {
				this.loading = false;
				this.$alert(error.message, "提示", { type: "error" });
				return false;
			}
		},
	},
	async mounted() {
		this.queryList.OrgCode=this.orgCode;
		await this.initOptions();
	},
};
</script>

<style scoped></style>
